<?php
class Like extends AppModel {
    public  $name = 'Like';
    public  $displayField = 'id';
    public $belongsTo = array(
		'User' => array(
			'className' => 'User',
			'foreignKey' => 'user_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);
    function checkLike($userId, $objectId, $objectType){
        $this->recursive = -1;
        $check = $this->find('count', array('conditions' => array( 'Like.user_id' => $userId, 'Like.object_id' => $objectId ,'Like.object_type' => $objectType)));
        if($check > 0){
            return true;
        }  else {
            return false;
        }
    }
    public function getLikes($ojectId, $objectType){
        $likes = $this->find('all', array('conditions' => array('Like.object_id' => $ojectId, 'Like.object_type' => $objectType), 'recursive' => 0, 'limit' => 6));
        return $likes;
    }
    public function totalLikes($ojectId, $objectType){
        $total = $this->find('count', array('conditions' => array('Like.object_id' => $ojectId, 'Like.object_type' => $objectType), 'recursive' => -1));
        return $total;
    }
}
?>